home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / mega src / Source / battery.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-19  |  2.1 KB  |  83 lines  |  [TEXT/KAHL]

  1. /* ========== the commmand file: ==========
  2.  
  3.     battery.c
  4.     
  5.     Copyright (c) 1993,1994 Newport Software Development
  6.     
  7.     You may distribute unmodified copies of this file for
  8.     noncommercial purposes.  You may use this file as a
  9.     reference when writing your own nShell(tm) commands.
  10.     
  11.     All other rights are reserved.
  12.     
  13.    ========== the commmand file: ========== */
  14.  
  15. #include <GestaltEqu.h>
  16. #include <power.h>
  17.                     
  18. #include "nshc.h"
  19.  
  20. #include "nshc_utl.proto.h"
  21.                     
  22. void main(t_nshc_parms *nshc_parms, t_nshc_calls *nshc_calls)
  23. {
  24.     OSErr    error;
  25.     char    recently;
  26.     char    lovoltage;
  27.     char    highrate;
  28.     char    connected;
  29.     long    response;
  30.     Byte    status;
  31.     Byte    power;
  32.     
  33.     if (nshc_bad_version( nshc_parms, nshc_calls, NSHC_VERSION )) return;
  34.     
  35.     nshc_parms->result = NSHC_ERR_GENERAL;        // preset return status to error
  36.     nshc_parms->action = nsh_idle;
  37.  
  38.     error = Gestalt( 'powr', &response );
  39.     
  40.     if (error) {
  41.         nshc_calls->NSH_printf_err("battery: The Gestalt call returned an error of %d.\r", error);
  42.         return; // error status is already set
  43.         }
  44.         
  45.     if ( !(response & ( 1 << gestaltPMgrExists ))) {
  46.         nshc_calls->NSH_putStr_err("\pbattery: The Power Manager is not installed.\r");
  47.         return; // error status is already set
  48.         }
  49.  
  50.     error = BatteryStatus( &status, &power );
  51.     
  52.     if (error) {
  53.         nshc_calls->NSH_printf_err("battery: The BatteryStatus call returned an error of %d.\r", error);
  54.         return; // error status is already set
  55.         }
  56.  
  57.     recently  = ( status & connChangedMask );
  58.     lovoltage = ( status & batteryLowMask );
  59.     highrate  = ( status & hiChargeMask );
  60.     connected = ( status & chargerConnMask );
  61.     
  62.     if (recently)
  63.         nshc_calls->NSH_puts("The charger has recently been");
  64.     else
  65.         nshc_calls->NSH_puts("The charger is");
  66.     
  67.     if (connected)
  68.         nshc_calls->NSH_puts(" connected.\r");
  69.     else
  70.         nshc_calls->NSH_puts(" disconnected.\r");
  71.     
  72.     if (lovoltage)
  73.         nshc_calls->NSH_puts("The low voltage flag is set.\r");        
  74.  
  75.     if (highrate)
  76.         nshc_calls->NSH_puts("The high charging rate flag is set.\r");
  77.     
  78.     nshc_calls->NSH_printf("Battery voltage is now %f V.\r", ((power/100.0)+5.12));
  79.  
  80.     nshc_parms->result = NSHC_NO_ERR;
  81.     nshc_parms->action = nsh_idle;
  82. }
  83.